<!DOCTYPE html>
<html lang="en-US">
  <head>
    <link href="/assets/index.css" rel="stylesheet" type="text/css" />
    <script crossorigin="anonymous" src="https://unpkg.com/@babel/standalone@7.8.7/babel.min.js"></script>
    <script crossorigin="anonymous" src="https://unpkg.com/react@16.8.6/umd/react.development.js"></script>
    <script crossorigin="anonymous" src="https://unpkg.com/react-dom@16.8.6/umd/react-dom.development.js"></script>
    <script crossorigin="anonymous" src="/test-harness.js"></script>
    <script crossorigin="anonymous" src="/test-page-object.js"></script>
    <script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script>
  </head>
  <body>
    <main id="webchat"></main>
    <script type="text/babel" data-presets="env,stage-3,react">
      run(async function () {
        const directLine = window.WebChat.createDirectLine({ token: await testHelpers.token.fetchDirectLineToken() });

        const store = testHelpers.createStoreWithOptions();

        window.WebChat.renderWebChat(
          {
            activityStatusMiddleware: () => next => args => {
              const nextRender = next(args);

              // "nextRender" may render a screen reader only timestamp. Thus, not returning falsy.
              // We should only prepend when "hideTimestamp" is not set.
              if (!args.hideTimestamp) {
                if (args.activity.from.role === 'user') {
                  return <span>User at {nextRender}</span>;
                }

                return <span>Bot at {nextRender}</span>;
              }

              return nextRender;
            },
            directLine,
            store
          },
          document.getElementById('webchat')
        );

        await pageConditions.uiConnected();
        await pageObjects.sendMessageViaSendBox('echo Hello, World!', { waitForSend: true });
        await pageConditions.minNumActivitiesShown(3);

        await host.snapshot();
      });
    </script>
  </body>
</html>
